package com.ddd.mill.query.dictionary;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ddd.mill.domain.aggregate.dictionary.entity.Dictionary;
import com.ddd.mill.api.dictionary.dto.response.DictionaryUnitListDto;
import com.ddd.mill.infrastructure.persistent.dao.dictionary.DictionaryDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class DictionaryQueryServiceMyBatisServiceImpl extends ServiceImpl<DictionaryDao, Dictionary> implements DictionaryQueryService {
    @Override
    public List<DictionaryUnitListDto> unitList() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("label", "unit");
        List<Dictionary> dictionaryList = this.list(queryWrapper);
        List<DictionaryUnitListDto> dictionaryResponseList = new ArrayList<>();
        for (Dictionary d : dictionaryList){
            DictionaryUnitListDto dictionaryUnitListDto = new DictionaryUnitListDto();
            dictionaryUnitListDto.setId(d.getId());
            dictionaryUnitListDto.setName(d.getVal());
            dictionaryResponseList.add(dictionaryUnitListDto);
        }
        return dictionaryResponseList;
    }
}
